import Vue from 'vue'
import Element from 'element-ui'
import App from '@/App'
import i18n from '@/i18n'
import router from '@/router'
import store from '@/store'
import '@/icons'
import '@/element-ui/theme/index.css'
import '@/assets/scss/aui.scss'
import http from '@/utils/request'
import { hasPermission, getDictLabel } from '@/utils'
import cloneDeep from 'lodash/cloneDeep'
import VueAMap from 'vue-amap'
import toTop from '@/assets/scss/js/comm.js'
import Quill from 'quill'
import VueQrcode from '@chenfengyuan/vue-qrcode'
import './assets/scss/fonts/iconfont.css'
import * as echarts from 'echarts'

import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'

Vue.prototype.$toTop = toTop
Vue.use(VXETable)

Vue.config.productionTip = false

Vue.use(Element, {
  size: 'default',
  i18n: (key, value) => i18n.t(key, value)
})
Vue.use(VueAMap)
VueAMap.initAMapApiLoader({
  key: '34be61f600c91e23d76cc28461e602be',
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  // 默认高德 sdk 版本为 1.4.4
  v: '1.4.15',
  protocol: protocol
})

Vue.component(VueQrcode.name, VueQrcode)

// 挂载全局
Vue.prototype.$echarts = echarts
Vue.prototype.$http = http
Vue.prototype.$hasPermission = hasPermission
Vue.prototype.$getDictLabel = getDictLabel

// 保存整站vuex本地储存初始状态
window.SITE_CONFIG.storeState = cloneDeep(store.state)

new Vue({
  i18n,
  router,
  store,
  render: h => h(App)
}).$mount('#app')
const BlockEmbed = Quill.import('blots/block/embed')
class ImgBlot extends BlockEmbed {
  static create (value) {
    const node = super.create()
    node.setAttribute('src', value.url)
    node.setAttribute('controls', value.controls)
    node.setAttribute('width', value.width)
    node.setAttribute('height', value.height)
    return node
  }

  static value (node) {
    return {
      url: node.getAttribute('src'),
      controls: node.getAttribute('controls'),
      width: node.getAttribute('width'),
      height: node.getAttribute('height')
    }
  }
}
ImgBlot.blotName = 'simpleImg'
ImgBlot.tagName = 'img'
Quill.register(ImgBlot)
